<?php

namespace App\Http\Controllers\Admin\Ranch;

use App\Exceptions\RanchException;
use App\Services\Admin\Ranch\ApplyService;
use Exception;
use Illuminate\Http\JsonResponse;

class ApplyController extends BaseRanchController
{

    protected ApplyService $applyService;

    /**
     * @throws Exception
     */
    public function __construct()
    {
        parent::__construct();
        $this->applyService = $this->loadService('Admin\Ranch\ApplyService');
    }

    /**
     * 申请列表
     * @return JsonResponse
     * @throws Exception
     */
    public function list(): JsonResponse
    {

        $list = $this->applyService->list($this->params);

        return outputJsonResult($list);
    }

    /**
     * 申请详情
     * @return JsonResponse
     * @throws RanchException
     */
    public function detail(): JsonResponse
    {
        $rule = [
            'id' => 'required|integer|min:1'
        ];
        if ($this->ruleCheck($rule)) {
            return outputJsonError();
        }

        $detail = $this->applyService->detail($this->params);
        return outputJsonResult($detail);
    }

    /**
     * 操作审核
     * @return JsonResponse
     * @throws RanchException
     */
    public function apply(): JsonResponse
    {
        $rule = [
            'id' => 'required|integer|min:1',
        ];

        if ($this->ruleCheck($rule)) {
            return outputJsonError();
        }

        $this->applyService->apply($this->params);
        return outputJsonResult();
    }

}
